// pages/auth/auth.js
import { login } from "../../utils/asyncWx.js"
Page({
  async handleGetUserInfo(e) {
    try {
      const { encryptedData, rawData, iv, signature } = e.detail;
      const { code } = await login();
      console.log(code);
      const loginParams = { encryptedData, rawData, iv, signature, code };
      const token = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo';
      // 写死的token，实际中应该用下面注释掉的从服务器获取
      // const token=await request({url:"/users/wxlogin",data:loginParams,method:"post"});
      wx.setStorageSync('token', token);
      wx.navigateBack({
        delta: 1 
      });
    } catch (error) {
      console.error('Login error:', error);

      wx.showToast({
        title: '登录失败，请重试',
        icon: 'none',
        duration: 2000
      });
    }
  }
});
